﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using BLL;

namespace BLL
{
  public class StatusBLL
  {
    public List<Status> GetAll()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.Status.ToList();
      }
    }
    public Status GetById(int id)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.Status.Where(p => p.Id == id).FirstOrDefault();
      }
    }
    public void Add(Status obj)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        data.Status.InsertOnSubmit(obj);
        data.SubmitChanges();
      }
    }
    public void Update(Status Status)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        Status obj = data.Status.Where(p => p.Id == Status.Id).FirstOrDefault();
        if (obj != null)
        {
          obj.Name = Status.Name;
          obj.Name_En = Status.Name_En;

        }
        data.SubmitChanges();
      }
    }
    public void Delete(int id)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        Status obj = data.Status.Where(p => p.Id == id).FirstOrDefault();
        if (obj != null)
        {
          data.Status.DeleteOnSubmit(obj);
          data.SubmitChanges();
        }
      }
    }
  }
}
